##1.清空内存
rm(list=ls())
gc()

##2.加载必要的R包
# library(knitr)
# library(tidyverse)
library(lifecontingencies)
# library(actuar)

##3.生成精算表

###3.1导入生命表
clt<-read.csv("ch4annuity\\lifetable_cn.csv")

###3.2生成生命表
clt<-probs2lifetable(clt$CL1,
                     radix=10^5,
                     type="qx")
###3.3生成精算表
clt.act<-new("actuarialtable",
             x=clt@x,
             lx=clt@lx,interest=0.03)

##4.计算年金现值

###4.1每年给付的终身年金
axn(clt.act,x=22,payment = "due")
axn(clt.act,x=22,payment = "immediate")

###4.2每年m次给付的终身年金
axn(clt.act,x=22,k=1,payment = "due")
axn(clt.act,x=22,k=12,payment = "due")
axn(clt.act,x=22,k=365,payment = "due")

###4.3定期年金
axn(clt.act,x=22,n=38,payment = "due")
axn(clt.act,x=22,n=38,payment ="immediate")

###4.4延期到60岁终身年金
axn(clt.act,x=22,m=38,payment = "due")
axn(clt.act,x=22,m=38,payment = "immediate")

